package com.g3d.core;

import java.util.ArrayList;

import com.g3d.objects.G3DMusic;

public class G3DMusicManager 
{

	private float _masterVolume = 1.0f;
	
	private Object _lock = new Object();
	private ArrayList<G3DMusic> _musics = new ArrayList<G3DMusic>();
	
	public float masterVolume()
	{
		return this._masterVolume;
	}
	
	public void masterVolume(float volume)
	{
		this._masterVolume = volume;
		
		synchronized (this._lock) 
		{
			for (G3DMusic music : this._musics) 
			{
				music.updateVolume();
			}
		}
	}
	
	public void addMusic(G3DMusic music)
	{
		synchronized (this._lock) 
		{
			this._musics.add(music);
		}
	}
	
	public void removeMusic(G3DMusic music)
	{
		music.destroy();
		synchronized (this._lock) 
		{
			this._musics.remove(music);
		}
	}
	
	public void destroy()
	{
		synchronized (_lock) 
		{
			for (G3DMusic music : _musics) 
			{
				music.destroy();
			}
			
			this._musics.clear();
		}
	}
}
